package client.comm.baoding.adapter

import android.content.Context
import android.content.Intent
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import client.comm.baoding.R
import client.comm.baoding.api.bean.TdBean
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.databinding.LayoutTdsubNewitemBinding
import client.comm.baoding.ui.TdSub2Activity
import client.comm.baoding.ui.TdlstjActivity
import client.comm.commlib.base.BaseLoadmoreAdapter
import client.comm.commlib.base.BindingViewHoder
import client.comm.commlib.utils.StoreUtil
import com.bumptech.glide.RequestManager

class TdSubAdapter : BaseLoadmoreAdapter<TdBean.Sub> {

    val manager: RequestManager

    constructor(context: Context, manager: RequestManager) : super(context) {
        this.manager = manager
    }

    override fun createVh(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.layout_tdsub_newitem,
                parent,
                false
            )
        )
    }


    override fun bindVh(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>

        val binding = bindingViewHolder.binding as LayoutTdsubNewitemBinding
        val bean = getItem(position)
        manager.load(bean.avatar).error(R.mipmap.ic_launcher_round).into(binding.img)
        binding.bean = bean
        binding.event = this

        binding.isShowLevel = !(bean.level_str == "" || bean.level_str.isEmpty())

    }

    fun onItemClick(b: TdBean.Sub) {
        context.startActivity(Intent(context, TdSub2Activity::class.java).apply {
            putExtra("bean", b.id)
        })
    }

    /**
     * 历史推荐
     */
    open fun lstj() {
//        startActivity(Intent(context, TdActivity::class.java).apply {
//            putExtra("bean", StoreUtil.getBean<UserInfo>(requireContext())!!.id)
//        })

        context.startActivity(Intent(context, TdlstjActivity::class.java)
            .apply {
                putExtra("bean", StoreUtil.getBean<UserInfo>(context)!!.id)
            }
        )
    }

}